#include <router/RouterControlClient.h>
#include <msg/response.h>
#include <router/RouterRequest.h>


RouterControlClient::RouterControlClient(std::string_view ip, uint16_t port):
    tcp_client(ip, port)
{
    connect();
}

bool RouterControlClient::create_forward_rule(forward_rule const& rule){
    request req = RouterRequest::create_forward_rule(rule);
    message::write_message_to(req, get_sockfd());
    auto [msg, is_valid] = message::read_message_from(get_sockfd());
    if (is_valid == false)
        return false;
    response resp = msg;
    return resp.get_head().code == response_code::SUCCESS;
}

void RouterControlClient::delete_forward_rule(forward_rule const& rule){
    // request req = RouterRequest::delete_forward_rule(rule);
    // message::write_message_to(req, get_sockfd());
}

